﻿<!-- @{
    ViewBag.Title = "信息设置";
}
@model GansuZhagangShowWeb.Areas.WeChat.Models.ModelAcceptanceMaintainWeiXin -->

<!DOCTYPE html>
<html>
  <head>
    <title>查岗确认</title>
	
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
	<script src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script>

<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Mk8h4HRD1DLT3wXGM6NbmObdP0rXV70D"></script>
<script src="Scripts/image-file-visible.js"></script>


    <link href="css/pages.css" rel="stylesheet" />
    <link href="css/Inspection.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            $("form").attr("enctype", "multipart/form-data");
        })
    $(document).ready(function () {
        //图片显示插件
        $.imageFileVisible({
            wrapSelector: "#image-wrap",
            fileSelector: "#file",
            width: "100%",
            height: "100%"
        });
    });

    function ChooseImg() {
        $("#file").click();
    }
</script>
</head>


<!-- @using (Html.BeginForm())
{
    @*@Html.HiddenFor(x => x.OpenID, new { id = "inputOpenid"})*@
    @Html.HiddenFor(x => x.ProjectID) -->
    
    <body>
    <div class="box" >
        <div class="pointlabel">
            <div class="label label-info" id="label-info">
              <!--   苏州市长桥 -->
            </div>
        </div>
<!--         @Html.TextBoxFor(x => x.Points, new { id="inputPoint",  @class = "form-control dateclass" })  
        @Html.HiddenFor(x => x.OpenID, new { id = "inputOpenid", @class = "form-control dateclass" }) -->
        <div>
            <input type="button" class="upphoto" value="上传照片" onclick="ChooseImg();">
            <input type="file" id="file" name="upfile" accept="image/*" capture="camera" value="上传照片" style="visibility:hidden" />
            <div id="image-wrap"></div>
        </div>
        <div style="width: 100%; margin: 10px auto; ">
            <button class="btn btn-primary" type="submit" onclick="replay()">
                	提交
            </button>
        </div>
    </div>
<!-- } -->
</body>
</html>

<script type="text/javascript">

	var pointlng = "";
	var pointlat = "";

	var checkInfoId = "";
	var code = "";
    $(function () {
    	
    	 //方法二：
  		 (function ($) {
    	   $.getUrlParam = function (name) {
    	       var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    	       var r = window.location.search.substr(1).match(reg);
    	       if (r != null) return unescape(r[2]); return null;
     	  }
		   })(jQuery);
			
	  	  code = $.getUrlParam('code');
    		
    	  checkInfoId = $.getUrlParam('checkInfoId');
    	
        // 百度地图API功能
     //   var backinfo = $("#hidbackinfo").val();
   //     if (backinfo.length!=0)
    //    {
    //        alert(backinfo);
  //      }
   //     var weixininfo = $("#hidweixininfo").val();
  //      var msg = eval("(" + weixininfo + ")");// $.parseJSON(data);
  //      var openid = msg.openid;
    //    openid = "N3vFdlSv27KphROQXdbJfs1";
        //TODO:PC测试使用
        //openid = "1234567";
  //      $("#inputOpenid").val(openid);

        var geolocation = new BMap.Geolocation();

        geolocation.getCurrentPosition(function (r) {
            if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                var mk = new BMap.Marker(r.point);
                pointlng = r.point.lng;
                pointlat = r.point.lat;
                $("#inputPoint").val(pointlng + ',' + pointlat);
                showPosition(r);
            }
            else {
                alert('failed' + this.getStatus());
            }
        },
        { enableHighAccuracy: true });
 
        $("#image-wrap").find("img").each(function () {
            $(this).css("height","100px;");
        });

        
        $("#inputPoint").attr("readonly", true).attr("placeholder", "请在消控室内自动获取经纬度");

        function showPosition(r) {                 //百度地图获取坐标及道路门牌信息；
            // ak = appkey 访问次数流量有限制
            var url = 'http://api.map.baidu.com/geocoder/v2/?ak=7b788c5ea45cc4b3ac6331a4b0643d5b&callback=?&location=' + r.point.lat + ',' + r.point.lng + '&output=json&pois=1';
            $.getJSON(url, function (res) {
                $("#msg").html(url);
                $("#label-info").text(res.result.addressComponent.city + res.result.addressComponent.district + res.result.addressComponent.street + res.result.addressComponent.streetNumber);
                //alert(res.result.addressComponent.city);  //百度地图获取道路门牌信息；
            });
        }
    })


    function replay(){
        	$.ajax({
                type: "POST", 
           	    url:"WeChatAction_check_replay.action",
             	data:{
             		code:code,
             		checkInfoId:checkInfoId,
             		lng:pointlng,
             		lat:pointlat
             	},
            	dataType:"json",
                 success: function (data) { 
                    msg = eval("(" + data + ")");
                    if (msg.msg == true) {
                        alert("提交成功！");
                        WeixinJSBridge.call("closeWindow");
                    } else if(msg.msg==false){
                        
                    }
                },
                error: function (err) {
                    alert("服务器异常，提交失败！！");
                }
            })
        };
    

</script>